//
//  TDWelconmeViewController.swift
//  微博
//
//  Created by tong dan on 16/3/7.
//  Copyright © 2016年 tong dan. All rights reserved.
//

import UIKit
import SDWebImage

class TDWelconmeViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    private func setupUI(){
        //设置view颜色
        view.backgroundColor = UIColor(white: 247/255, alpha: 1)
        //添加子控件
        view.addSubview(headImage)
        view.addSubview(messagelabel)
        
        //添加约束
        headImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view)
            make.top.equalTo(self.view).offset(200)
            make.size.equalTo(CGSizeMake(90, 90))
            
        }
        
        messagelabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(15)
        }
        
    }
    
    
    //设置动画效果
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        //更新图像的约束
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(100)
        }
        //执行动画
        UIView.animateWithDuration(3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            self.messagelabel.alpha = 1
            self.headImage.alpha = 1
            
            }) { (_) -> Void in
                
                //弹性动画执行完毕
                UIView.animateWithDuration(2.5, animations: { () -> Void in
                    
                    
                    }, completion: { (_) -> Void in
                        
                        //跳转界面 --->首页
                        print("跳转界面")
                        NSNotificationCenter.defaultCenter().postNotificationName(TDSwitchRootVCNotification, object: nil)
                })
        }
    }
    
    //头像
    private lazy var headImage:UIImageView = {
        
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        //加载图片
        imageView.sd_setImageWithURL(NSURL(string: TDUserAccountViewModel.shareViewModel.account?.avatar_large ?? "avatar_default_big"))
        
        print("\(TDUserAccountViewModel.shareViewModel.account?.avatar_large)")
        
        imageView.layer.cornerRadius = 45
        imageView.layer.masksToBounds = true
        
        return imageView
        
    }()
    
    //消息
    private lazy var messagelabel:UILabel = {
        
        let label = UILabel(textColor: UIColor.grayColor(), fontSize: 16)
        
        label.text = "欢迎回来"
        label.alpha = 0
        return label
        
    }()
}
